import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../../pages/sdzx/sdzx_data_ss.dart';
import '../../pages/sdzx/sdzx_work.dart';
import '../gmap/gmap.dart';
import '../station/station_map.dart';
import '../../widgets/dialogWidget.dart';
import '../../helper/routeHelper.dart';
import '../../helper/uidata.dart';

import 'sdzx_data.dart';
import 'sdzx_map.dart';

class SdzxHomePage extends StatefulWidget {
  @override
  createState() => new SdzxHomePageState();
}

class SdzxHomePageState extends State<SdzxHomePage> {
//  定义底部导航列表
  final List<BottomNavigationBarItem> bottomTabs = [
    new BottomNavigationBarItem(
        icon: new Icon(Icons.dashboard), label: ('实时数据')),
    new BottomNavigationBarItem(
        icon: new Icon(FontAwesomeIcons.map), label: ('工作台')),
    new BottomNavigationBarItem(
        icon: new Icon(Icons.location_on), label: ('流域降雨')),
  ];

  Widget getBody(int i) {
    //if (i == 1) return DCSSDataPage();
    if (i == 1) return SdzxWorkPage();
    if (i == 2) return SdzxMapPage();
    if (i == 0) return SdzxDataPage();
    return new Container();
  }

  final titleList = ["实时数据", "工作台", "流域降雨"];
  int currentIndex = 0; //当前索引
  late Widget currentPage; //当前页面

  @override
  void initState() {
    super.initState();
    currentPage = getBody(0);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        // title: bottomTabs[currentIndex].title,
        title: Text(titleList[currentIndex]),
        actions: <Widget>[
          ElevatedButton(
              child: Icon(
                Icons.exit_to_app,
                color: Colors.white,
              ),
              onPressed: () {
                showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return DialogWidget.getDialog(
                          context, "退出登录", "点击确定将退出登录", () {
                        RouteHelper.exitLogin(context);

                        ;
                      });
                    });
              })
        ],
        // leading: Icon(Icons.menu),
      ),
      bottomNavigationBar: SafeArea(
          top: true,
          child: BottomNavigationBar(
              type: BottomNavigationBarType.fixed,
              currentIndex: currentIndex,
              items: bottomTabs,
              fixedColor: Colors.blue,
              onTap: (index) {
                setState(() {
                  currentIndex = index;
                  currentPage = getBody(currentIndex);
                });
              })),
      body: SafeArea(top: true, child: currentPage),
    );
  }
}
